package com.cdut.logistics.model.dao.datacentre;

import java.util.Date;

import com.cdut.logistics.model.entity.BaseModel.BaseDorm;
import com.cdut.logistics.model.entity.datacentre.BaseArea;
import com.jfinal.plugin.activerecord.Db;

/**  
 * @ClassName: Dorm
 * @Description: 操作数据库 
 * @author wxt.asus
 * @date 2018年1月26日 上午9:13:52    
 */
public class Dorm extends BaseDorm<Dorm>{
	private static final long serialVersionUID = 1L;
	public String baseSql = " and is_use = 1";
	public String sql1 = "SELECT "+
			"dorm.id,"+
			"dorm.`name`,"+
			"area.name as 'a_name', "+
			"school.name as 's_name' "+
			"FROM dorm join school "+
			"ON dorm.school_id=school.id AND school.is_use =1 "+
			"join area "+
			"ON dorm.area_id=area.id "+
			"AND dorm.is_use = 1 "+
			"AND area.is_use = 1 "+
			"AND dorm.area_id = ?";
	public String sql2 = "UPDATE dorm set name =?, updated=? where id =?"+ baseSql;
	public String sql3 = "UPDATE dorm set is_use =?, updated=? where id =?"+ baseSql;
	/**  
	 * @Title: save  
	 * @Description: 新增寝室
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void save(Dorm area) {
		area.set("created", new Date());
		area.set("updated", new Date());
		area.set("is_use", 1);
		area.set("active", 1);
		area.save();
	}

	/**  
	 * @Title: update  
	 * @Description: 修改寝室
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void update(Dorm dorm) {
		dorm.set("updated", new Date());
		Db.update(sql2,dorm.get("name"),dorm.get("updated"),dorm.get("id"));
	}

	/**  
	 * @Title: remove  
	 * @Description: 删除寝室
	 * @author wxt.xia
	 * @param id
	 * @throws  
	 */
	public void remove(int id) {
		Db.update(sql3,0,new Date(),id);
	}
}
